# -*- coding: utf-8 -*-
# @Time    : 2021/8/31 16:51
# @Author  : BrandonGT
# @FileName: 08_PyQt5_QButtonGroup.py

# 1. 导入包和模块
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys

# 2. 创建一个应用程序对象
app = QApplication(sys.argv)

# 3. 创建控件
window = QWidget()

# 3.1 设置控件
window.setWindowTitle("")
window.resize(500, 500)

# 创建4个单选空间
# 第一组
r1 = QRadioButton("1", window)
r2 = QRadioButton("2", window)
r1.move(100, 100)
r2.move(100, 150)
r1.setChecked(True)

group1 = QButtonGroup(window)
group1.addButton(r1, 1)
group1.addButton(r2, 2)

# 第二组
r3 = QRadioButton("3", window)
r4 = QRadioButton("4", window)
r3.move(200, 100)
r4.move(200, 150)

# 获取按钮组信息
print(group1.buttons())
print(group1.button(1))

# 3.2 展示控件
window.show()

# 4. 应用程序执行，进入消息循环
sys.exit(app.exec_())